//******************************************************************************
//* DeGsoft GeN                                                                *
//* ===========                                                                *
//* GeN(tm) : ERP Software (http://www.degsoft.com.ar/sistemas/GeN)            *
//* Copyright (c) 2002-2011 by the Degsoft                                     *
//* For more information visit: http://www.degsoft.com.ar                      *
//* This program is free software. You can redistribute it and/or modify       *
//* it under the terms of the GNU General Public License as published by       *
//* the Free Software Foundation; either version 3 of the License.             *
//******************************************************************************

unit VerCobranza;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Grids, DBGrids, DB, ImprimirDM, Mask, DBCtrls, StdCtrls, Buttons,
  ComCtrls, RpCon, RpConDS, RpRender, RpRenderCanvas, RpRenderPrinter, RpBase,
  RpSystem, RpDefine, RpRave, DataModule, IBCustomDataSet, IBQuery, jpeg;

type
  TVerCobranzaForm = class(TForm)
    Panel3: TPanel;
    Label1: TLabel;
    Panel1: TPanel;
    Label16: TLabel;
    ImprimirBitBtn: TBitBtn;
    CodigoDBText: TDBText;
    NombreDBText: TDBText;
    SeleccionarBitBtn: TBitBtn;
    DiasEdit: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    DBGrid1: TDBGrid;
    DS: TDataSource;
    GrillaQ: TIBQuery;
    Tabla: TIBQuery;
    Image1: TImage;
    procedure CancelarBitBtnClick(Sender: TObject);
    procedure SeleccionarBitBtnClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure DBGrid1Enter(Sender: TObject);
    procedure ImprimirBitBtnClick(Sender: TObject);
    procedure DiasEditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Image1Click(Sender: TObject);
  private
    { Private declarations }
  public
  fecha:string;
    { Public declarations }
  end;

var
  VerCobranzaForm: TVerCobranzaForm;

implementation

{$R *.dfm}

procedure TVerCobranzaForm.CancelarBitBtnClick(Sender: TObject);
begin
close;
end;

procedure TVerCobranzaForm.DBGrid1DblClick(Sender: TObject);
begin
   SeleccionarBitBtnClick(DBGrid1);
end;

procedure TVerCobranzaForm.DBGrid1Enter(Sender: TObject);
begin
   SeleccionarBitBtnClick(DBGrid1);
end;

procedure TVerCobranzaForm.DiasEditKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if DiasEdit.Text <> '' then
 begin
Fecha := FormatDateTime('mm/dd/yyyy', (now-StrToInt(DiasEdit.Text)));
GrillaQ.SQL.Text:='SELECT'+
'  "CtaCteItem".VENCE,'+
'  "Cliente".NOMBRE,'+
'  "CtaCteItem".CUOTA,'+
'  "CtaCteItem".PAGADO,'+
'  "CtaCteItem".IMPORTE,'+
'  "CtaCteItem".DESCRIPCION,'+
'  "CtaCte".CLIENTE,'+
'  "CtaCte".COBRANZA,'+
'  "CtaCte".OPERACION'+
' FROM'+
'  "CtaCte"'+
'  INNER JOIN "Cliente" ON ("CtaCte".CLIENTE = "Cliente".CODIGO)'+
'  INNER JOIN "CtaCteItem" ON ("CtaCte".OPERACION = "CtaCteItem".OPERACION)'+
' WHERE'+
'  ("CtaCteItem".PAGADO < "CtaCteItem".IMPORTE) AND'+
'  ("CtaCteItem".VENCE < '+QuotedStr(fecha)+') AND'+
'  (("CtaCte".COBRANZA is null) OR ("CtaCte".COBRANZA=1))'+
' ORDER BY'+
'  "CtaCteItem".VENCE'+
'';
GrillaQ.Open;
 end;
end;

procedure TVerCobranzaForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   IF Key = VK_DOWN then
   DbGrid1.SetFocus;
end;

procedure TVerCobranzaForm.Image1Click(Sender: TObject);
begin
 ImprimirDataModule := TImprimirDataModule.Create(self);
 ImprimirDataModule.CSV(Tabla.SQL.Text,'ARTICULOS');
 ImprimirDataModule.Free;
end;

procedure TVerCobranzaForm.ImprimirBitBtnClick(Sender: TObject);
begin
 ImprimirDataModule:=TImprimirDataModule.Create(self);
 ImprimirDataModule.SImpr(GrillaQ.SQL.Text, 'DeudoresPorCredito');
 ImprimirDataModule.Free;
end;

procedure TVerCobranzaForm.SeleccionarBitBtnClick(Sender: TObject);
begin
close;
end;

end.
